package com.iwop.moto.service.impl;

import com.iwop.moto.model.SuperRecordModel;
import com.iwop.moto.service.BaseService;
import com.iwop.moto.service.IDataService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author huyuangui on 2016/7/25.
 */
@Service("dataService")
public class DataServiceImpl extends BaseService implements IDataService {
    private static String baseMapper="FDataMapper.";
    private static String findDataByParent="findDataByParent";

    @Override
    public List<SuperRecordModel> findDataByParent(String parentname) {
        SuperRecordModel superRecordModel=new SuperRecordModel();
        superRecordModel.put("parentname",parentname);
        List<SuperRecordModel> list=getSqlSession().selectList(baseMapper+findDataByParent,superRecordModel);
        return list;
    }

    /**
     *
     * @param codetype 字典组类型
     */
    public List<SuperRecordModel> findListByCodeType(String codetype){
        SuperRecordModel srm = new SuperRecordModel();
        srm.put("codetype",codetype);
        return getSqlSession().selectList("FDataMapper.findListByCodeType",srm);
    }

    public List<SuperRecordModel> findListByCodeType(SuperRecordModel srm){
        return getSqlSession().selectList("FDataMapper.findListByCodeType",srm);
    }

    @Override
    public SuperRecordModel findDataByCodeTypeEx(SuperRecordModel srm) {
        return getSqlSession().selectOne("FDataMapper.findDataByCodeTypeEx", srm);
    }

    @Override
    public void addData(SuperRecordModel srModel) {
        getSqlSession().insert("FDataMapper.insert",srModel);
    }

    @Override
    public List<SuperRecordModel> findDataParentNode(SuperRecordModel srm) {
        return getSqlSession().selectList("FDataMapper.findDataParentNode",srm);
    }

    @Override
    public void deleteData(SuperRecordModel srModel) {
        getSqlSession().insert("FDataMapper.deleteByPrimaryKey",srModel);
    }

    @Override
    public void updateData(SuperRecordModel srModel) {
        getSqlSession().update("FDataMapper.update", srModel);
    }

    @Override
    public SuperRecordModel getDataDetail(SuperRecordModel srModel) {
        return getSqlSession().selectOne("FDataMapper.getDataDetail",srModel);
    }
}
